package org.afun.csms_android.adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.csms_android.LoginActivity;
import org.afun.csms_android.MainActivity;
import org.afun.csms_android.R;
import org.afun.csms_android.RecordScoreActivity;
import org.afun.csms_android.UserAlterActivity;
import org.afun.csms_android.domain.User;
import org.afun.csms_android.domain.javaBean.TS;
import org.afun.csms_android.utils.MyTableOperator;
import org.afun.csms_android.utils.TableOperator;

import java.util.List;

public class TeacherStudentAdapter extends RecyclerView.Adapter<TeacherStudentAdapter.ViewHolder> {
    private static List<TS> mTSList;
    private Context context;

    static class ViewHolder extends RecyclerView.ViewHolder {
        View TSView;
        ImageView User_imageTS;
        TextView TS_msg;

        public ViewHolder(View view) {
            super(view);
            TSView = view;
            User_imageTS = (ImageView) view.findViewById(R.id.User_imageTS);
            TS_msg = view.findViewById(R.id.TS_msg);
        }

    }

    public TeacherStudentAdapter(List<TS> mTSList, Context context) {
        TeacherStudentAdapter.mTSList = mTSList;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tsitem, parent, false);
        ViewHolder holder = new ViewHolder(view);

        holder.TSView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                TS ts = mTSList.get(position);

                Intent intent = new Intent(context, RecordScoreActivity.class);
                // 传递TS
                Bundle bundle = new Bundle();
                bundle.putSerializable("ts", ts);
                intent.putExtras(bundle);
                context.startActivity(intent);

//                Toast.makeText(v.getContext(), "you clicked view " + ts.getSsId(), Toast.LENGTH_SHORT).show();
            }
        });


        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TS ts = mTSList.get(position);
        holder.User_imageTS.setImageResource(R.drawable.name);


        holder.TS_msg.setText(
                "学生号：" + ts.getStuId()
                        + "\n学生姓名：" + ts.getStuName()
                        + "\n性别：" + ts.getGender()
                        + "\n所选课程号：" + ts.getCouId()
                        + "\n所选课程名：" + ts.getCouName()
                        + "\n成绩：" + ts.getScore());
    }

    @Override
    public int getItemCount() {
        return mTSList.size();
    }
}
